import { Context, DependencyContainer, Inject, getDependency, storeName } from ".."
import { ButtonView } from "./button"
import { ViewComponent } from "./components"
import { ContainerView } from "./container"
import { InputView } from "./input"
import { TextView } from "./text"

// 组件工厂
export class ComponentFactory {
  static createComponent(data: any, context: Context): ViewComponent {
    switch (data.key) {
      case "InputBox":
        return new InputView(data?.option?.placeholder || '请输入')
      case 'InputButton':
        return new ButtonView(data?.option?.dataset || '按钮', () => {
          const action = getDependency(storeName)
          console.log('这是测试数据传递的，要删掉的', action)
          if (action.count) action.count += 1
          else action.count = 1
          
        })
      case 'HeaderContainer':
        return new ContainerView(data?.columns?.[0]?.list || [], context)
      default:
        throw new Error('组件类型不存在')
    }
  }
}